package com.test;

/**
 * @Description:
 * @Auther: liuyanhui
 * @Date: 2024/03/12/ 15:42
 */
public class DoublyLinkedList {
    private DoublyListNode head;
    private DoublyListNode tail;
    public void insert(int value){
        DoublyListNode node = new DoublyListNode(value);
        if (head == null){
            head = node;
            tail = node;
        }else {
            tail.next = node;
            node.prev = tail;
            tail = node;
        }
    }
    public void delete(int value){
        DoublyListNode node = head;
        while (node != null){
            if (node.value == value){
                if (node == head && node == tail){
                    head = null;
                    tail = null;
                }else if (node == head){
                    head = head.next;
                    head.prev = null;
                }else if (node == tail){
                    tail = tail.prev;
                    tail.next = null;
                }else {
                    node.prev.next = node.next;
                }
            }
        }
    }

}
